export default {
    mounted(el, binding) {
        const {value} = binding;
        const {arg} = binding;
        let userinfo = JSON.parse(localStorage.getItem('userinfo'));
        console.log(userinfo);
        if (userinfo.type !== 0) {
            let flag = true;
            if (arg === 'role') {
                for (let role in userinfo.roles) {
                    if (value instanceof Array) {
                        for (let permission in value) {
                            if (role === permission) {
                                flag = false;
                                break;
                            }
                        }
                    } else {
                        if (role === value) {
                            flag = false;
                            break;
                        }
                    }
                }
            }
            if (arg === 'permissions') {
                for (let permission in userinfo.permissions) {
                    if (value instanceof Array) {
                        for (let item in value) {
                            if (permission === item) {
                                flag = false;
                                break;
                            }
                        }
                    } else {
                        if (permission === value) {
                            flag = false;
                            break;
                        }
                    }
                }
            }
            if (flag) {
                el.parentNode.removeChild(el);
            }
        }
    }
}
